#include "D2d1Source.h"

D2d1Source::D2d1Source() {
}

BOOL D2d1Source::CreateDeviceDependentResource(HWND hwnd) {
	HRESULT hr = NULL;
	RECT rc;
	GetClientRect(hwnd, &rc);
	D2D1_SIZE_U size = D2D1::SizeU(rc.right - rc.left, rc.bottom - rc.top);
	hr = pD2DFactory->CreateHwndRenderTarget(
		D2D1::RenderTargetProperties(),
		D2D1::HwndRenderTargetProperties(hwnd, size), 
		&pD2DRenderTarget);
	if (SUCCEEDED(hr)) {
		hr = pD2DRenderTarget->CreateSolidColorBrush(
			D2D1::ColorF(D2D1::ColorF::OrangeRed), &pSolidBrush);
	}
	return SUCCEEDED(hr);
}

BOOL D2d1Source::CreateDeviceIndependentResource() {
	HRESULT hr = NULL;
	hr = D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, &pD2DFactory);
	return SUCCEEDED(hr);
}

D2d1Source::~D2d1Source() {
}

void D2d1Source::SizeUpdate(HWND hwnd) {
	RECT rc;
	GetClientRect(hwnd, &rc);
	pD2DRenderTarget->Resize(
		D2D1::SizeU(rc.right - rc.left, rc.bottom - rc.top));
}
